package leetcode;

import java.util.HashMap;

public class Lc1679 {

    public int maxOperations(int[] nums, int k) {
        int ans = 0;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            int cnt = map.getOrDefault(k - num, 0);
            if (cnt > 0) {
                ans++;
                map.put(k - num, cnt - 1);
            } else {
                map.merge(num, 1, Integer::sum);
            }
        }
        return ans;
    }
}
